/**********************************************************************
***********************************************************************
* Software that is described herein is for illustrative purposes only
* which provides customers with programming information regarding the
* products. This software is supplied "AS IS" without any warranties.
* NXP Semiconductors assumes no responsibility or liability for the
* use of the software, conveys no license or title under any patent,
* copyright, or mask work right to the product. NXP Semiconductors
* reserves the right to make changes in the software without
* notification. NXP Semiconductors also make no representation or
* warranty that such application will be suitable for the specified
* use without further testing or modification.
* Permission to use, copy, modify, and distribute this software and its
* documentation is hereby granted, under NXP Semiconductors�
* relevant copyright in the software, without fee, provided that it
* is used in conjunction with NXP Semiconductors microcontrollers.  This
* copyright, permission, and disclaimer notice must appear in all copies of
* this code.
**********************************************************************/

#ifndef lpc8xx_I2C_H_
#define lpc8xx_I2C_H_

#include "lpc8xx.h"
#include "board.h"
#include "gpio.h"
#include"stdint.h"

#ifndef HIGH
	#define HIGH  		1
#endif

#ifndef LOW
	#define LOW 		0
#endif

#ifndef INPUT
	#define INPUT  0
#endif

#ifndef OUTPUT
	#define OUTPUT 1
#endif

#define I2C_SLAVE_ADDRESS7     0xA0
//#define I2C_EE_SIZE            0x80
#define I2C_EE_SIZE            0x100


#define		IOCON_SCL	IOCON_PIO10
#define		IOCON_SDA	IOCON_PIO11

#define SCL_H          LPC_GPIO_PORT->B0[10] = 1
//GPIOSetBitValue(  0,  10,  1 )

#define SCL_L        LPC_GPIO_PORT->B0[10] = 0

#define SDA_H        LPC_GPIO_PORT->B0[11] = 1
#define SDA_L        LPC_GPIO_PORT->B0[11] = 0

#define SCL_read       Chip(10)
#define SDA_read        Chip(11)
//GPIOGetPinValue(  0,  11 )
#define I2C_PageSize  8  //24C02Ã¿Ò³8×Ö½Ú

void I2C_GPIO_Config(void);

void I2C_delay(void);
uint8_t I2C_Start(void);
void I2C_Stop(void);
void I2C_Ack(void);
void I2C_NoAck(void);
uint8_t I2C_WaitAck(void) ;
void EEP_MemoryReset(void);
void EEP_SoftReset(void);
void I2C_SendByte(uint8_t SendByte);
uint8_t I2C_ReceiveByte(void);

uint8_t	I2C_WriteByte(uint8_t SendByte, uint16_t WriteAddress, uint8_t DeviceAddress);
uint8_t	I2C_BufferWrite(uint8_t* pBuffer, uint16_t length, uint16_t WriteAddress, uint8_t DeviceAddress);
uint8_t	I2C_PageWrite(uint8_t* pBuffer, uint16_t length, uint16_t WriteAddress, uint8_t DeviceAddress);
uint8_t	I2C_ReadByte(uint8_t* pBuffer,   uint16_t length, uint16_t ReadAddress,  uint8_t DeviceAddress);
static __inline _Bool Chip(uint32_t pin);
#endif






